package com.tvein.sanguo.event.controller
{
	//flash
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.event.common.GameConstants;
	import com.tvein.sanguo.event.model.SystemProxy;
	import com.tvein.sanguo.event.view.EventMediator;
//
	public class EventInit extends SimpleFabricationCommand implements ICommand
	{
		private var systemData:SystemProxy;
		private var eventMediator:EventMediator;
		
		override public function execute(notification:INotification) : void
		{
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			eventMediator = facade.retrieveMediator(EventMediator.NAME) as EventMediator;
			
			switch(notification.getBody()[0])
			{
				case "roomName":
					systemData.roomName = notification.getBody()[1];
					
					if (systemData.getScript().length > 0)
					{
						if (!systemData.eventFreeze)
						{
							sendNotification(GameConstants.EVENT_RUN, ["start"]);
						}
					}
					
					break;
				case "srcServer":
					systemData.srcServer = notification.getBody()[1];
					break;
				case "effectVol":
					systemData.effectVol = notification.getBody()[1];
					break;
				case "freeze":
					systemData.eventFreeze = notification.getBody()[1];
					
					if (!systemData.eventFreeze)
					{
						for (var key:String in systemData.getScript())
						{
							sendNotification(GameConstants.EVENT_RUN, ["start"]);
							break;
						}
					}
					break;
			}
		}
	}
}